{template 'header', 'member'}
<div class="menu">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="tab" id="add"><a href="?action=list"><span>购买排名</span></a></td>
<td class="tab" id="s3"><a href="?action=index"><span>已通过({$nums[3]})</span></a></td>
<td class="tab" id="s2"><a href="?status=2"><span>审核中({$nums[2]})</span></a></td>
<td class="tab"><a href="{$EXT[spread_url]}"><span>推广中心</span></a></td>
</tr>
</table>
</div>
{if $action == 'add'}
<form method="post" action="?" onsubmit="return check();">
<input type="hidden" name="mid" value="{$mid}"/>
<input type="hidden" name="word" value="{$word}"/>
<input type="hidden" name="action" value="{$action}"/>
<table cellpadding="10" cellspacing="1" class="tb">
<tr>
<td class="tl">关键词</td>
<td class="tr"><a href="{$MODULE[$mid][linkurl]}{rewrite('search.php?kw='.urlencode($word))}" class="b" target="_blank">{$word}</a></td>
</tr>
<tr>
<td class="tl">所属频道</td>
<td class="tr"><a href="{$MODULE[$mid][linkurl]}" class="b" target="_blank">{$MODULE[$mid][name]}</a></td>
</tr>
<tr>
<td class="tl">最低出价</td>
<td class="tr f_red">{$price}{$unit}</td>
</tr>
<tr>
<td class="tl">加价幅度</td>
<td class="tr">{if $step}{$step}{$unit}{else}不限{/if}</td>
</tr>
<tr>
<td class="tl"><span class="f_red">*</span> 我的出价</td>
<td class="tr"><input type="text" name="buy_price" value="{$price}" size="10" id="price" onkeyup="CA();"/> <span id="dprice" class="f_red"></span></td>
</tr>
<tr>
<td class="tl"><span class="f_red">*</span> 购买时长</td>
<td class="tr">
<select name="buy_month" id="month" onchange="CA();">
{php for($i=1;$i<=$month;$i++){}
<option value="{$i}">{$i}月</option>
{php }}
</select>
</td>
</tr>
<tr>
<td class="tl"><span class="f_red">*</span> 信息ID</td>
<td class="tr">
<input type="text" name="buy_tid" value="{if $mid==4}{$_userid}{/if}" size="10" id="key_id" onfocus="select_item({$mid}, 'member');"/> <span id="dkey_id" class="f_red"></span>
</td>
</tr>
<tr>
<td class="tl">应付总额</td>
<td class="tr"><span id="money" class="f_price px16">{$price}</span>{$unit}</td>
</tr>

{if $currency == 'money'}
<tr id="mymoney" style="display:none;">
<td class="tl">账户余额</td>
<td class="tr"><span class="f_blue">{$_money}</span> {$DT[money_unit]}</td>
</tr>
<tr id="payword" style="display:none;">
<td class="tl"><span class="f_red">*</span> 支付密码</td>
<td class="tr">{template 'password', 'chip'}&nbsp;<span id="dpassword" class="f_red"></span></td>
</tr>
<tr id="paytype" style="display:none;">
<td class="tl"><span class="f_red">*</span> 支付方式</td>
<td class="tr">
	<table cellspacing="5" cellpadding="5">
	{php $PAYLIST = get_paylist();}
	<input type="hidden" name="bank" id="bank" value="{$PAYLIST[0][bank]}"/>
	{loop $PAYLIST $k $v}
	<tr onclick="$('#bank').val($('#paytype :checked').val());">
	<td><input type="radio" name="bank" value="{$v[bank]}" id="bank-{$v[bank]}"{if $k==0} checked{/if}/></td>
	<td><label for="bank-{$v[bank]}" class="c_p"><img src="{DT_PATH}api/pay/{$v[bank]}/logo.gif" alt=""/></label></td>
	<td>{if $v[percent]>0}手续费 {$v[percent]}%{/if}</td>
	</tr>
	{/loop}
	</table>
</td>
</tr>
{else}
<tr>
<td class="tl">{$DT[credit_name]}余额</td>
<td class="tr"><span class="f_blue f_b">{$_credit}{$unit}</span>&nbsp;&nbsp;<a href="credit.php?action=buy" target="_blank" class="t">[购买]</a></td>
</tr>
{/if}
<tr>
<td class="tl"> </td>
<td class="tr"><input type="submit" name="submit" value="确定购买" class="btn_g"/>&nbsp;
<input type="button" value="重新选择" class="btn" onclick="Go('?action=list&mid={$mid}&kw={urlencode($word)}');"/>
</td>
</tr>
</table>
</form>
<script type="text/javascript">s('spread');m('add');</script>
{elseif $action == 'list'}
<form action="?" onsubmit="return check();">
<input type="hidden" name="action" value="add"/>
<table cellpadding="10" cellspacing="1" class="tb">
<tr>
<td class="tl"><span class="f_red">*</span> 关键词：</td>
<td class="tr"><input type="text" name="kw" size="20" id="kw" value="{$kw}"/> <span id="dkw" class="f_red"></span></td>
</tr>
<tr>
<td class="tl"><span class="f_red">*</span> 频道：</td>
<td class="tr">
<select name="mid">
{loop $MODULE $m}
{if $m[moduleid] > 3 && !$m[islink]}<option value="{$m[moduleid]}"{if $mid==$m[moduleid]} selected{/if}>{$m[name]}</option>{/if}
{/loop}
</select>
</td>
</tr>
<tr>
<td class="tl"> </td>
<td class="tr"><input type="submit" value="下一步" class="btn_g"/>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function check() {
	if(Dd('kw').value.length < 2) {
		Dmsg('请填写关键词', 'kw');
		return false;
	}
	return true;
}
</script>
<script type="text/javascript">s('spread');m('add');</script>
{else}
<div class="ls">
<table cellpadding="10" cellspacing="0" class="tb">
<tr>
<th>关键词</th>
<th>模块</th>
<th>出价</th>
<th>单位</th>
<th>开始日期</th>
<th>结束日期</th>
<th>剩余(天)</th>
<th>投放状态</th>
<th>申请时间</th>
<th>信息</th>
</tr>
{loop $lists $k $v}
<tr align="center">
<td><a href="{$EXT[spread_url]}{rewrite('index.php?kw='.urlencode($v['word']))}" target="_blank" class="b">{$v[word]}</a></td>
<td><a href="{$MODULE[$v[mid]][linkurl]}{rewrite('search.php?kw='.urlencode($v['word']))}" target="_blank" class="b">{$MODULE[$v[mid]][name]}</a></td>
<td>{$v[price]}</td>
<td>{if $v[currency]=='money'}{$DT[money_unit]}{else}{$DT[credit_unit]}{/if}</td>
<td>{timetodate($v[fromtime], 3)}</td>
<td>{timetodate($v[totime], 3)}</td>
<td{if $v[days]<5} class="f_red"{/if}>{$v[days]}</td>
<td>{$v[process]}</td>
<td class="f_gray">{timetodate($v[addtime], 5)}</td>
<td><a href="{DT_PATH}api/redirect.php?mid={$v[mid]}&itemid={$v[tid]}" target="_blank" class="b">直达</a></td>
</tr>
{/loop}
</table>
</div>
<div class="pages">{$pages}</div>
<script type="text/javascript">s('spread');m('s{$status}');</script>
{/if}
{if $action == 'add'}
<script type="text/javascript">
function CA() {
	if(Dd('price').value.match(/^[0-9]{1,}$/)) {
		Dd('money').innerHTML = Dd('price').value*Dd('month').value;
	} else {
		Dd('price').value = '{$price}';
	}
}
function check() {
	var p = Dd('price').value;
	if(p < {$price}) {
		Dmsg('出价不能低于起价', 'price');
		return false;
	}
	if((p-{$price})%{$step} != 0) {
		Dmsg('请按加价幅度加价', 'price');
		return false;
	}
	if(Dd('key_id').value.length < 1) {
		Dmsg('请填写信息ID', 'key_id');
		return false;
	}
	{if $currency == 'money'}
	var money = p*Dd('month').value;
	if(p*Dd('month').value > {$_money}) {
		Go('charge.php?action=pay&reason=spread|{$mid}|{$_word}|'+p+'|'+Dd('month').value+'|'+Dd('key_id').value+'&amount='+money+'&bank='+$('#bank').val());
		return false;
	}
	if(money > {$DT[quick_pay]}){
		if(Dd('password').value.length < 6) {
			Dmsg('请填写支付密码', 'password');
			return false;
		}
	}
	{else}
	if(p*Dd('month').value > {$_credit}) {
		alert('您的{$DT[credit_name]}不足，请先购买');
		return false;
	}
	{/if}
}

{if $currency == 'money'}
window.setInterval(
	function() {
		var money = Dd('price').value*Dd('month').value;
		if(money > {$_money} || {$_money} < 0.01) {
			$('#mymoney').hide();$('#paytype').show();$('#payword').hide();
		} else {
			$('#mymoney').show();$('#paytype').hide();if(money > {$DT[quick_pay]}){$('#payword').show();}
		}
	}, 
500);
{/if}
</script>
{/if}
{template 'footer', 'member'}